package com.thread;

public class Threadnoisyandwait {
    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (Threadnoisyandwait.class) {
                    for (int i = 0; i < 5; i++) {
                        Threadnoisyandwait.class.notify();  // 唤醒
                        System.out.println(Thread.currentThread().getName() + "吃第" + i +  "口" );
                        try {
                            Threadnoisyandwait.class.wait(); // 等待
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                }
            }
        },"杨过").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (Threadnoisyandwait.class) {
                    for (int i = 0; i < 5; i++) {
                        Threadnoisyandwait.class.notify();  // 唤醒
                        System.out.println(Thread.currentThread().getName() + "吃第" + i +  "口" );
                        try {
                            Threadnoisyandwait.class.wait(); // 等待
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }



                }
            }
        },"小龙女").start();


    }
}
